<?php

//以下代码在命令行里测试通过

require('DB.php'); //只需引入此文件

//获取一个db, 作为一切操作的入口
$db = DB::build('models/', (new MongoClient())->test);

//创建一个user模块
$userId = $db->users->create();

//更新info
$db->users->info->update($userId, [
    'name' => 'xiaoming',
    'portrait' => 'xxx'
]);

//更新info.portrait, 只需传入一个字符串
$db->users->info->portrait->update($userId, 'www');

//find user
$db->users->find($userId);

//find user info
$info = $db->users->info->find($userId);

var_dump($info == ['name' => 'xiaoming', 'portrait' => 'www']);

//find with fields limit
$info = $db->users->info->find($userId, ['name', 'portrait']);

var_dump($info == ['name' => 'xiaoming', 'portrait' => 'www']);

$name = $db->users->info->name->find($userId);

var_dump($name == 'xiaoming');

print_r($db->users->findBy([
    'fields' => ['stat.createTime', 'info.name', 'info.protrait'],
    'cond' => ['info.name' => 'xiaoming'],
    'orderBy' => 'stat.createTime asc',
    'skip' => 0,
    'limit' => 1
]));

print_r($db->users->info->findBy([
    'fields' => ['name', 'portrait'],
    'cond' => ['name' => 'xiaoming'],
    'orderBy' => '.stat.createTime dsc',
    'skip' => 1,
    'limit' => 2
]));

$db->labs->findBy(['skip' => 0, 'limit' => 1]);

$db->labs->papers->findBy(['skip' => 0, 'limit' => 1]);
